#include <cstdio>
#include <iostream>
#include <queue>

using namespace std; 

#define N  		102
#define INF 	0xf0000000

int a[N][N]; 
int s[N][N]; 		//steps
int n, m; 

int g_dir[4][2] = {
	{1, 0}, {0, 1}, {-1, 0}, {0, -1}
}; 

int dfs(int x, int y)
{
	int i, j, d, ss; 
	if (s[x][y]>0)
		return s[x][y]; 
	s[x][y] = 1; 
	for (d=0; d<4; d++) {
		i = x + g_dir[d][0]; 
		j = y + g_dir[d][1]; 
		if (i<0 || i>n-1 || j<0 || j>m-1) 
			continue; 
		if (a[i][j]>=a[x][y])
			continue; 
		ss = 1 + dfs(i, j); 
		s[x][y] = max(s[x][y], ss); 
	}
	return s[x][y]; 
}

int main()
{
	int i, j, d, x, y; 
	int ix=0, jx=0, sx=0, r; 

	//freopen("p1434_1.in", "r", stdin); 
	//freopen("a.txt", "r", stdin); 
	cin>>n>>m; 
	for (i=0; i<n; i++) {
		for (j=0; j<m; j++) {
			cin>>a[i][j]; 
		}
	}

	sx = 0;
	for (ix=0; ix<n; ix++) {
		for (jx=0; jx<m; jx++) {
			s[ix][jx] = dfs(ix, jx); 
			sx = max(sx, s[ix][jx]); 
		}
	}

	printf("%d", sx); 
	return 0; 
}


